﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using StyleMVVM.Data.Activation;
using StyleMVVM.DependencyInjection;
using Windows.Data.Xml.Dom;
using Windows.UI.Notifications;

namespace StyleMVVM.Notification.Tile
{
	public sealed class TileService : ITileService, IActivationAware
	{
		private TileUpdater updater;

		public static void RegisterExport(IDependencyInjectionContainer container)
		{
			container.Register(typeof(TileService)).
			          As(typeof(ITileService)).
			          AndSharedPermenantly();
		}

		public void Activate()
		{
			updater = TileUpdateManager.CreateTileUpdaterForApplication();
		}

		public ITileSquareImage CreateTileSquareImage()
		{
			return new TileSquareImage();
		}

		public ITileSquareBlock CreateTileSquareBlock()
		{
			return new TileSquareBlock();
		}

		public ITileSquareText01 CreateTileSquareText01()
		{
			return new TileSquareText01();
		}

		public ITileSquareText02 CreateTileSquareText02()
		{
			return new TileSquareText02();
		}

		public ITileSquareText03 CreateTileSquareText03()
		{
			return new TileSquareText03();
		}

		public ITileSquareText04 CreateTileSquareText04()
		{
			return new TileSquareText04();
		}

		public ITileSquarePeekImageAndText01 CreateTileSquarePeekImageAndText01()
		{
			return new TileSquarePeekImageAndText01();
		}

		public ITileSquarePeekImageAndText02 CreateTileSquarePeekImageAndText02()
		{
			return new TileSquarePeekImageAndText02();
		}

		public ITileSquarePeekImageAndText03 CreateTileSquarePeekImageAndText03()
		{
			return new TileSquarePeekImageAndText03();
		}

		public ITileSquarePeekImageAndText04 CreateTileSquarePeekImageAndText04()
		{
			return new TileSquarePeekImageAndText04();
		}

		public ITileWideImageCollection CreateTileWideImageCollection()
		{
			return new TileWideImageCollection();
		}

		public ITileWideImageAndText01 CreateTileWideImageAndText01()
		{
			return new TileWideImageAndText01();
		}

		public ITileWideImageAndText02 CreateTileWideImageAndText02()
		{
			return new TileWideImageAndText02();
		}

		public ITileWideImage CreateTileWideImage()
		{
			return new TileWideImage();
		}

		public ITileWideBlockAndText01 CreateTileWideBlockAndText01()
		{
			return new TileWideBlockAndText01();
		}

		public ITileWideBlockAndText02 CreateTileWideBlockAndText02()
		{
			return new TileWideBlockAndText02();
		}

		public ITileWidePeekImageCollection01 CreateTileWidePeekImageCollection01()
		{
			return new TileWidePeekImageCollection01();
		}

		public ITileWidePeekImageCollection02 CreateTileWidePeekImageCollection02()
		{
			return new TileWidePeekImageCollection02();
		}

		public ITileWidePeekImageCollection03 CreateTileWidePeekImageCollection03()
		{
			return new TileWidePeekImageCollection03();
		}

		public ITileWidePeekImageCollection04 CreateTileWidePeekImageCollection04()
		{
			return new TileWidePeekImageCollection04();
		}

		public ITileWidePeekImageCollection05 CreateTileWidePeekImageCollection05()
		{
			return new TileWidePeekImageCollection05();
		}

		public ITileWidePeekImageCollection06 CreateTileWidePeekImageCollection06()
		{
			return new TileWidePeekImageCollection06();
		}

		public ITileWidePeekImageAndText01 CreateTileWidePeekImageAndText01()
		{
			return new TileWidePeekImageAndText01();
		}

		public ITileWidePeekImageAndText02 CreateTileWidePeekImageAndText02()
		{
			return new TileWidePeekImageAndText02();
		}

		public ITileWidePeekImage01 CreateTileWidePeekImage01()
		{
			return new TileWidePeekImage01();
		}

		public ITileWidePeekImage02 CreateTileWidePeekImage02()
		{
			return new TileWidePeekImage02();
		}

		public ITileWidePeekImage03 CreateTileWidePeekImage03()
		{
			return new TileWidePeekImage03();
		}

		public ITileWidePeekImage04 CreateTileWidePeekImage04()
		{
			return new TileWidePeekImage04();
		}

		public ITileWidePeekImage05 CreateTileWidePeekImage05()
		{
			return new TileWidePeekImage05();
		}

		public ITileWidePeekImage06 CreateTileWidePeekImage06()
		{
			return new TileWidePeekImage06();
		}

		public ITileWideSmallImageAndText01 CreateTileWideSmallImageAndText01()
		{
			return new TileWideSmallImageAndText01();
		}

		public ITileWideSmallImageAndText02 CreateTileWideSmallImageAndText02()
		{
			return new TileWideSmallImageAndText02();
		}

		public ITileWideSmallImageAndText03 CreateTileWideSmallImageAndText03()
		{
			return new TileWideSmallImageAndText03();
		}

		public ITileWideSmallImageAndText04 CreateTileWideSmallImageAndText04()
		{
			return new TileWideSmallImageAndText04();
		}

		public ITileWideSmallImageAndText05 CreateTileWideSmallImageAndText05()
		{
			return new TileWideSmallImageAndText05();
		}

		public ITileWideText01 CreateTileWideText01()
		{
			return new TileWideText01();
		}

		public ITileWideText02 CreateTileWideText02()
		{
			return new TileWideText02();
		}

		public ITileWideText03 CreateTileWideText03()
		{
			return new TileWideText03();
		}

		public ITileWideText04 CreateTileWideText04()
		{
			return new TileWideText04();
		}

		public ITileWideText05 CreateTileWideText05()
		{
			return new TileWideText05();
		}

		public ITileWideText06 CreateTileWideText06()
		{
			return new TileWideText06();
		}

		public ITileWideText07 CreateTileWideText07()
		{
			return new TileWideText07();
		}

		public ITileWideText08 CreateTileWideText08()
		{
			return new TileWideText08();
		}

		public ITileWideText09 CreateTileWideText09()
		{
			return new TileWideText09();
		}

		public ITileWideText10 CreateTileWideText10()
		{
			return new TileWideText10();
		}

		public ITileWideText11 CreateTileWideText11()
		{
			return new TileWideText11();
		}

		public void Clear()
		{
			updater.Clear();
		}

		public IReadOnlyList<ScheduledTileNotification> GetScheduledTileNotifications()
		{
			return updater.GetScheduledTileNotifications();
		}

		public void EnableNotificationQueue(bool enabled)
		{
			updater.EnableNotificationQueue(enabled);
		}

		public ScheduledTileNotification AddToSchedule(ITileUpdate update, DateTimeOffset offSet)
		{
			string tileString = string.Format("<tile><visual>{0}</visual></tile>", update.GenerateXML());

			XmlDocument document = new XmlDocument();

			document.LoadXml(tileString);

			ScheduledTileNotification returnValue = new ScheduledTileNotification(document, offSet);

			updater.AddToSchedule(returnValue);

			return returnValue;
		}

		public void RemoveFromSchedule(ScheduledTileNotification notification)
		{
			updater.RemoveFromSchedule(notification);
		}

		public void StartPeriodicUpdate(Uri uri, PeriodicUpdateRecurrence recurrence)
		{
			updater.StartPeriodicUpdate(uri, recurrence);
		}

		public void StartPeriodicUpdate(Uri uri, DateTimeOffset startOffSet, PeriodicUpdateRecurrence recurrence)
		{
			updater.StartPeriodicUpdate(uri, startOffSet, recurrence);
		}

		public void StopPeriodicUpdate()
		{
			updater.StopPeriodicUpdate();
		}

		public void Update(ITileUpdate update)
		{
			string tileString = string.Format("<tile><visual>{0}</visual></tile>", update.GenerateXML());

			XmlDocument document = new XmlDocument();

			document.LoadXml(tileString);

			updater.Update(new TileNotification(document));
		}
	}
}